package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.Hotel;
import com.example.demo.entity.Hotel;
import com.example.demo.service.HotelService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: demo
 * @description:
 * @author: Lelouch
 * @create: 2024-09-05 15:47
 **/
@CrossOrigin
@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Resource
    private HotelService hotelService;

    @GetMapping("/list")
    public Result list(){
        PageInfo<Hotel> hotelList = hotelService.list();
        if(hotelList != null){
            return Result.success(hotelList);
        }
        else {
            return Result.error("酒店列表为空!");
        }
    }

    @GetMapping("/search")
    public Result search(@RequestParam String hotelname,@RequestParam String city){
        List<Hotel> hotelList = hotelService.search(hotelname,city);
        if(hotelList != null){
            return Result.success(hotelList);
        }
        else {
            return Result.error("酒店列表为空!");
        }
    }

    /**
     * test:目前未添加推荐算法
     * @return
     */
    @GetMapping("/recommend")
    public Result recommend(){
        PageInfo<Hotel> hotelList = hotelService.list();
        if(hotelList != null){
            return Result.success(hotelList);
        }
        else {
            return Result.error("推荐酒店列表为空!");
        }
    }
}
